//
//  CYWithdrawDateCell.m
//  cyjf
//
//  Created by tauCross on 2017/12/29.
//  Copyright © 2017年 Auto Financing. All rights reserved.
//

#import "CYWithdrawDateCell.h"



@implementation CYWithdrawDateCellObject

@end



@interface CYWithdrawDateCell ()

@property(nonatomic, strong)UILabel *dateLabel;

@end


@implementation CYWithdrawDateCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self)
    {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.contentView.backgroundColor = [UIColor whiteColor];
        
        self.dateLabel = [[UILabel alloc] init];
        self.dateLabel.numberOfLines = 0;
        [self.contentView addSubview:self.dateLabel];
    }
    return self;
}

+ (CGFloat)heightForObject:(CYWithdrawDateCellObject *)object atIndexPath:(NSIndexPath *)indexPath tableView:(UITableView *)tableView
{
    UILabel *label = [[UILabel alloc] init];
    label.numberOfLines = 0;
    if(object.date)
    {
        label.attributedText = ({
            NSMutableAttributedString *string = [[NSMutableAttributedString alloc] init];
            [string appendAttributedString:[[NSAttributedString alloc] initWithString:@"预计到账时间：" attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:12 weight:UIFontWeightRegular], NSForegroundColorAttributeName : HEXCOLOR(@"999999")}]];
            [string appendAttributedString:[[NSAttributedString alloc] initWithString:[object.date cy_stringWithFormat:@"yyyy-MM-dd HH:mm"] attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:12 weight:UIFontWeightRegular], NSForegroundColorAttributeName : HEXCOLOR(@"E94559")}]];
            [string appendAttributedString:[[NSAttributedString alloc] initWithString:@"(若为法定节假日顺延)" attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:12 weight:UIFontWeightRegular], NSForegroundColorAttributeName : HEXCOLOR(@"999999")}]];
            string;
        });
    }
    return MIN(40, [label sizeThatFits:CGSizeMake(SCREEN_WIDTH - 40, MAXFLOAT)].height + 20);
}

- (BOOL)shouldUpdateCellWithObject:(CYWithdrawDateCellObject *)object
{
    if(object.date)
    {
        self.dateLabel.attributedText = ({
            NSMutableAttributedString *string = [[NSMutableAttributedString alloc] init];
            [string appendAttributedString:[[NSAttributedString alloc] initWithString:@"预计到账时间：" attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:12 weight:UIFontWeightRegular], NSForegroundColorAttributeName : HEXCOLOR(@"999999")}]];
            [string appendAttributedString:[[NSAttributedString alloc] initWithString:[object.date cy_stringWithFormat:@"yyyy-MM-dd HH:mm"] attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:12 weight:UIFontWeightRegular], NSForegroundColorAttributeName : HEXCOLOR(@"E94559")}]];
            [string appendAttributedString:[[NSAttributedString alloc] initWithString:@"(若为法定节假日顺延)" attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:12 weight:UIFontWeightRegular], NSForegroundColorAttributeName : HEXCOLOR(@"999999")}]];
            string;
        });
    }
    else
    {
        self.dateLabel.attributedText = nil;
    }
    
    [self setNeedsLayout];
    return YES;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.dateLabel.size = [self.dateLabel sizeThatFits:CGSizeMake(SCREEN_WIDTH - 40, MAXFLOAT)];
    self.dateLabel.centerY = self.contentView.height / 2;
    self.dateLabel.left = 20;
}

@end
